<!DOCTYPE html>

<html lang='en'>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/react.development16.4.0.js"></script>
    <script src="./lib/react-dom.development16.4.0.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="app">
    </div>
    <script type="text/babel">
        class MyComponent extends React.Component {
            handleClick() {
                // 使用原生的 DOM API 获取焦点
                this.refs.myInput.focus();
            }
            render() {
                //  当组件插入到 DOM 后，ref 属性添加一个组件的引用于到 this.refs
                return (
                <div>
                    <input type="text" ref="myInput" />
                    <input
                    type="button"
                    value="点我输入框获取焦点"
                    onClick={this.handleClick.bind(this)}
                    />
                </div>
                );
            }
            }
 
        ReactDOM.render(
        <MyComponent />,
        document.getElementById('app')
        );
    </script>
</body>

</html>